package com.example.skywalking.controller;

import com.example.skywalking.dto.Response;
import com.example.skywalking.entity.User;
import com.example.skywalking.service.IUserService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class SkyWalkingController {

    @Autowired
    private IUserService userService;

    @RequestMapping("/send")
    public String send() throws JsonProcessingException {
        List<User> list = userService.list();
        Response<List<User>> success = Response.success(list);
        ObjectMapper mapper = new ObjectMapper();
        String asString = mapper.writeValueAsString(success);
        log.info(asString);
        return asString;
    }
}
